#include <vector>
#include <iostream>
#include <string>
#include <queue>
using namespace std;


class Solution {
public:
    int LastRemaining_Solution(int n, int m) {
        // write code here
        vector<int> vt(n + 1, 0);
        int p = n;
        int i = 0;
        int k = 0;
        while (p > 1)
        {
            if (vt[i] == 0)
            {
                k++;
            }
            if (k == m)
            {
                while (vt[i] == 1)
                {
                    i++;
                    if (i == n)
                    {
                        i = 0;
                    }
                }
                vt[i] = 1;
                k = 0;
                p--;
            }
            i++;
            if (i == n)
            {
                i = 0;
            }
        }
        for (int q = 0; q < n; q++)
        {
            if (vt[q] == 0)
            {
                return q;
            }
        }
        return 0;
    }
};
//
//int main()
//{
//    Solution s;
//    s.LastRemaining_Solution(5, 3);
//    return 0;
//}

class Solution {
public:
    int m, n;
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    bool dfs[1010][1010] = { 0 };
    int rotApple(vector<vector<int> >& grid) {
        // write code here
        m = grid.size();
        n = grid[0].size();
        queue<pair<int, int>> q;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (grid[i][j] == 2)
                {
                    q.push(pair<int, int>(i, j));
                }
            }
        }
        int ret = 0;
        while (!q.empty())
        {
            ret++;
            int sz = q.size();
            while (sz--)
            {
                pair<int, int> k = q.front();
                q.pop();
                for (int i = 0; i < 4; i++)
                {
                    int x = k.first + dx[i];
                    int y = k.second + dy[i];
                    if (x >= 0 && x < m && y >= 0 && y < n && !dfs[x][y] && grid[x][y] == 1)
                    {
                        dfs[x][y] = true;
                        q.push(pair<int, int>(x, y));
                    }
                }
            }
        }
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (grid[i][j] == 1 && !dfs[i][j])
                {
                    return -1;
                }
            }
        }
        return ret - 1;
    }
};


int main() {
    int n;
    while (cin >> n)
    {
        while (n--)
        {
            int a, b, c;
            cin >> a >> b >> c;
            int sum = 0;;;
            int x = min(a, min(b, c));
            sum += max(max(a - 1 - x, max(b - 1 - x, c - 1 - x)), 0);
            cout << (sum += (x * 2)) << endl;
        }
    }
    return 0;
}

struct ListNode 
{
    int val;
    struct ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
};

class Solution {
public:
    ListNode* SwapListNode(ListNode* phead)
    {
        ListNode* prev = nullptr;
        ListNode* cur = phead;
        while (cur)
        {
            ListNode* next = cur->next;
            cur->next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }
    ListNode* addInList(ListNode* head1, ListNode* head2) {
        // write code here
        if (!head1 || !head2)
        {
            return head1 == nullptr ? head2 : head1;
        }
        ListNode* cur = nullptr;
        ListNode* phead = nullptr;
        ListNode* root1 = SwapListNode(head1);
        ListNode* root2 = SwapListNode(head2);
        int k = 0;
        while (root1 && root2)
        {
            int n = root1->val + root2->val + k;
            k = n / 10;
            ListNode* p = new ListNode(n %= 10);
            if (phead == nullptr)
            {
                phead = cur = p;
            }
            else
            {
                cur->next = p;
                cur = cur->next;
            }
            ListNode* next1 = root1->next;
            delete root1;
            root1 = next1;
            ListNode* next2 = root2->next;
            delete root2;;
            root2 = next2;
        }
        while (root1)
        {
            int n = root1->val + k;
            k = n / 10;
            ListNode* p = new ListNode(n %= 10);
            ListNode* next1 = root1->next;
            delete root1;
            root1 = next1;
            cur->next = p;
            cur = cur->next;
        }
        while (root2)
        {
            int n = root2->val + k;
            k = n / 10;
            ListNode* p = new ListNode(n %= 10);
            ListNode* next2 = root2->next;
            delete root2;;
            root2 = next2;
            cur->next = p;
            cur = cur->next;
        }
        if (k)
        {
            cur->next = new ListNode(k);
        }
        return SwapListNode(phead);
    }
};


class Solution {
public:
    string solve(string s, string t) {
        // write code here
        int n1 = s.size();
        int n2 = t.size();
        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
        int k = 0;
        int i = 0;
        string str;
        while (i < n1 && i < n2)
        {
            int st = s[i] - '0' + t[i] - '0' + k;
            k = st / 10;
            str += (st % 10 + '0');
            i++;
        }
        if (n1 > i)
        {
            str += ((s[i] - '0' + k) % 10 + '0');
            k = (s[i] - '0' + k) / 10;
            i++;
        }
        if (n2 > i)
        {
            str += ((t[i] - '0' + k) % 10 + '0');
            k = (t[i] - '0' + k) / 10;
            i++;
        }
        if (k == 1)
        {
            str += '1';
        }
        reverse(str.begin(), str.end());
        return str;
    }
};

#include <iterator>
class Solution {
public:
    string solve(string s, string t) {
        // write code here
        int n1 = s.size() - 1;
        int n2 = t.size() - 1;
        int k = 0;
        string str;
        while (n1 >= 0 || n2 >= 0 || k)
        {
            int sum = k;
            if (n1 >= 0)
            {
                sum += s[n1--] - '0';
            }
            if (n2 >= 0)
            {
                sum += t[n2--] - '0';
            }
            str += (sum % 10 + '0');
            k = sum / 10;
        }
        reverse(str.begin(), str.end());
        return str;
    }
};

class Solution {
public:
    string solve(string s, string t) {
        // write code here
        int n1 = s.size();
        int n2 = t.size();
        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
        vector<int> vt(n1 + n2);
        for (int i = 0; i < n1; i++)
        {
            for (int j = 0; j < n2; j++)
            {
                vt[i + j] += ((s[i] - '0') * (t[j] - '0'));
            }
        }
        int p = 0;
        string str;
        for (auto x : vt)
        {
            p += x;
            str += (p % 10 + '0');
            p /= 10;
        }
        while (p)
        {
            str += (p % 10 + '0');
            p /= 10;
        }
        while (str.size() > 1 && str.back() == '0')
        {
            str.pop_back();
        }
        reverse(str.begin(), str.end());
        return str;
    }
};
